/*   1:    */ package org.intellij.plugins.relaxNG.compact.psi.util;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.PsiManager;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.HashSet;
import com.sun.org.apache.xerces.internal.util.XML11Char;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;
import org.intellij.plugins.relaxNG.compact.RncFileType;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;
import org.intellij.plugins.relaxNG.compact.psi.RncFile;
import org.intellij.plugins.relaxNG.compact.psi.RncGrammar;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */ 
/*  18:    */ public class RenameUtil
/*  19:    */ {
/*  20:    */   private static Set<String> a;
/*  21:    */   
/*  22:    */   static
/*  23:    */   {
/*  24: 42 */     a = new HashSet();
/*  25:    */     
/*  26:    */ 
/*  27: 45 */     Collections.addAll(a, new String[] { "attribute", "default", "datatypes", "div", "element", "empty", "external", "grammar", "include", "inherit", "list", "mixed", "namespace", "notAllowed", "parent", "start", "string", "text", "token" });
/*  28:    */   }
/*  29:    */   
/*  30:    */   @NotNull
/*  31:    */   public static ASTNode createIdentifierNode(PsiManager paramPsiManager, String paramString)
/*  32:    */     throws IncorrectOperationException
/*  33:    */   {
/*  34: 55 */     if (isKeyword(paramString)) {
/*  35: 56 */       paramString = "\\" + paramString;
/*  36: 57 */     } else if (!isIdentifier(paramString)) {
/*  37: 58 */       throw new IncorrectOperationException("Illegal identifier: " + paramString);
/*  38:    */     }
/*  39: 61 */     PsiFileFactory localPsiFileFactory = PsiFileFactory.getInstance(paramPsiManager.getProject());
/*  40: 62 */     RncFile localRncFile = (RncFile)localPsiFileFactory.createFileFromText("dummy.rnc", RncFileType.getInstance(), paramString + " = bar");
/*  41: 63 */     ASTNode localASTNode1 = a(localRncFile);
/*  42: 64 */     ASTNode localASTNode2 = localASTNode1.findChildByType(RncTokenTypes.IDENTIFIERS);
/*  43: 65 */     assert (localASTNode2 != null); ASTNode 
/*  44: 66 */       tmp143_141 = localASTNode2;
/*  45: 66 */     if (tmp143_141 == null) {
/*  46: 66 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/util/RenameUtil", "createIdentifierNode" }));
/*  47:    */     }
/*  48: 66 */     return tmp143_141;
/*  49:    */   }
/*  50:    */   
/*  51:    */   public static boolean isIdentifier(String paramString)
/*  52:    */   {
/*  53: 71 */     if (paramString == null) {
/*  54: 72 */       return false;
/*  55:    */     }
/*  56: 74 */     if (XML11Char.isXML11ValidNCName(paramString)) {
/*  57: 75 */       return true;
/*  58:    */     }
/*  59: 77 */     return (paramString.length() >= 2) && (paramString.startsWith("\\")) && (XML11Char.isXML11ValidNCName(paramString.substring(1)));
/*  60:    */   }
/*  61:    */   
/*  62:    */   public static boolean isKeyword(String paramString)
/*  63:    */   {
/*  64: 82 */     return a.contains(paramString);
/*  65:    */   }
/*  66:    */   
/*  67:    */   public static ASTNode createPrefixedNode(PsiManager paramPsiManager, String paramString1, String paramString2)
/*  68:    */   {
/*  69: 97 */     PsiFileFactory localPsiFileFactory = PsiFileFactory.getInstance(paramPsiManager.getProject());
/*  70: 98 */     RncFile localRncFile = (RncFile)localPsiFileFactory.createFileFromText("dummy.rnc", RncFileType.getInstance(), "element " + paramString1 + ":" + paramString2 + " { text }");
/*  71:    */     
/*  72:100 */     ASTNode localASTNode1 = a(localRncFile);
/*  73:101 */     ASTNode localASTNode2 = localASTNode1.findChildByType(RncElementTypes.NAME_CLASS);
/*  74:102 */     assert (localASTNode2 != null);
/*  75:    */     
/*  76:104 */     ASTNode localASTNode3 = localASTNode2.findChildByType(RncElementTypes.NAME);
/*  77:105 */     assert (localASTNode3 != null);
/*  78:106 */     return localASTNode3;
/*  79:    */   }
/*  80:    */   
/*  81:    */   @NotNull
/*  82:    */   private static ASTNode a(RncFile paramRncFile)
/*  83:    */   {
/*  84:111 */     RncGrammar localRncGrammar = paramRncFile.getGrammar();
/*  85:112 */     assert (localRncGrammar != null);
/*  86:113 */     ASTNode localASTNode1 = localRncGrammar.getNode();
/*  87:114 */     assert (localASTNode1 != null);
/*  88:115 */     ASTNode localASTNode2 = localASTNode1.getFirstChildNode();
/*  89:116 */     assert (localASTNode2 != null); ASTNode 
/*  90:117 */       tmp76_75 = localASTNode2;
/*  91:117 */     if (tmp76_75 == null) {
/*  92:117 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/compact/psi/util/RenameUtil", "findFirstGrammarNode" }));
/*  93:    */     }
/*  94:117 */     return tmp76_75;
/*  95:    */   }
/*  96:    */   
/*  97:    */   public static ASTNode createLiteralNode(PsiManager paramPsiManager, String paramString)
/*  98:    */   {
/*  99:121 */     PsiFileFactory localPsiFileFactory = PsiFileFactory.getInstance(paramPsiManager.getProject());
/* 100:122 */     RncFile localRncFile = (RncFile)localPsiFileFactory.createFileFromText("dummy.rnc", RncFileType.getInstance(), "include \"" + paramString + "\"");
/* 101:    */     
/* 102:124 */     ASTNode localASTNode1 = a(localRncFile);
/* 103:125 */     ASTNode localASTNode2 = localASTNode1.findChildByType(RncTokenTypes.LITERAL);
/* 104:126 */     assert (localASTNode2 != null);
/* 105:127 */     return localASTNode2;
/* 106:    */   }
/* 107:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.psi.util.RenameUtil

 * JD-Core Version:    0.7.0.1

 */